import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, OneToMany } from 'typeorm';
import { Chat } from './Chat';
import { ChatGroup } from './ChatGroup';
import { GroupMember } from './GroupMember';

@Entity('users')
export class User {
  // 主键
  @PrimaryGeneratedColumn()
  id!: number;

  // 用户名 唯一
  @Column({ length: 50, unique: true })
  account!: string;

  // 密码
  @Column({ length: 255 })
  password!: string;

  // 邮箱
  @Column({ length: 100, nullable: true })
  email?: string;

  // 头像
  @Column({ length: 255, nullable: true })
  avatar?: string;

  // 昵称
  @Column({ length: 255, nullable: true })
  nickname?: string;

  // 性别
  @Column({ length: 10, nullable: true })
  gender?: string;

  // 生日
  @Column({ length: 20, nullable: true })
  birthday?: string;

  @CreateDateColumn()
  createdAt!: Date;

  @Column({ 
    type: 'datetime',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP'
  })
  updatedAt!: Date;

  @Column({ type: 'tinyint', default: 1 })
  status!: number;

  @OneToMany(() => Chat, chat => chat.sender)
  sentChats!: Chat[];

  @OneToMany(() => Chat, chat => chat.receiver)
  receivedChats!: Chat[];

  @OneToMany(() => ChatGroup, group => group.creator)
  createdGroups!: ChatGroup[];

  @OneToMany(() => GroupMember, member => member.user)
  groupMemberships!: GroupMember[];
} 